package salary

// 添加员工事务
type AddEmployeeTransaction struct {
	Transaction
	EmpId   int
	Name    string
	Address string
	// 获取支付策略
	GetPaymentClassification func() PaymentClassification
	// 获取支付时间表
	GetPaymentSchedule func() PaymentSchedule
}

// 执行事务
func (t *AddEmployeeTransaction) Execute() {
	employee := Employee{
		Name:                  t.Name,
		Address:               t.Address,
		EmployeeId:            t.EmpId,
		Affiliation:           NoAffiliation{},
		PaymentMethod:         &HoldMethod{},
		PaymentClassification: t.GetPaymentClassification(),
		PaymentSchedule:       t.GetPaymentSchedule(),
	}
	GetDB().AddEmployee(employee)
}

func GetAddEmployeeTransaction(employeeId int, name string, address string) *AddEmployeeTransaction {
	return &AddEmployeeTransaction{
		EmpId:   employeeId,
		Name:    name,
		Address: address,
	}
}

// 销售型
type AddCommissionedEmployee struct {
	AddEmployeeTransaction
	MonthSalary    float64
	CommissionRate float64
}

// CommissionedEmployee
func GetCommissionedEmployee(employeeId int, name string, address string, monthSalary float64, commissionRate float64) *AddCommissionedEmployee {
	a := &AddCommissionedEmployee{
		*GetAddEmployeeTransaction(employeeId, name, address),
		monthSalary,
		commissionRate,
	}
	a.AddEmployeeTransaction.GetPaymentSchedule = a.GetPaymentSchedule
	a.AddEmployeeTransaction.GetPaymentClassification = a.GetPaymentClassification
	return a
}

// 获取支付分类
func (t *AddCommissionedEmployee) GetPaymentClassification() PaymentClassification {
	return &CommissionedClassification{
		MonthlySalary:  t.MonthSalary,
		CommissionRate: t.CommissionRate,
		SalesReceipts:  make([]SalesReceipt, 10),
	}
}

// 获取支付时间表
func (t *AddCommissionedEmployee) GetPaymentSchedule() PaymentSchedule {
	return &BiWeeklySchedule{}
}

// 小时型
type AddHourlyEmployeeTransaction struct {
	AddEmployeeTransaction
	hourlyRate float64
}

// 新建NewCommissionedEmployee
func NewHourlyEmployee(employeeId int, name string, address string, hourlyRate float64) *AddHourlyEmployeeTransaction {
	a := &AddHourlyEmployeeTransaction{
		*GetAddEmployeeTransaction(employeeId, name, address),
		hourlyRate,
	}
	a.AddEmployeeTransaction.GetPaymentSchedule = a.GetPaymentSchedule
	a.AddEmployeeTransaction.GetPaymentClassification = a.GetPaymentClassification
	return a
}

// 获取支付分类
func (t *AddHourlyEmployeeTransaction) GetPaymentClassification() PaymentClassification {
	return &HourlyClassification{
		HourlyRate: t.hourlyRate,
	}
}

// 获取支付时间表
func (t *AddHourlyEmployeeTransaction) GetPaymentSchedule() PaymentSchedule {
	return &WeeklySchedule{}
}

// 月薪
type AddSalariedEmployee struct {
	AddEmployeeTransaction
	MonthSalary    float64
}

// CommissionedEmployee
func GetAddSalariedEmployee(employeeId int, name string, address string, monthSalary float64) *AddSalariedEmployee {
	a := &AddSalariedEmployee{
		*GetAddEmployeeTransaction(employeeId, name, address),
		monthSalary,
	}
	a.AddEmployeeTransaction.GetPaymentSchedule = a.GetPaymentSchedule
	a.AddEmployeeTransaction.GetPaymentClassification = a.GetPaymentClassification
	return a
}

// 获取支付分类
func (t *AddSalariedEmployee) GetPaymentClassification() PaymentClassification {
	return &CommissionedClassification{
		MonthlySalary:  t.MonthSalary,
	}
}

// 获取支付时间表
func (t *AddSalariedEmployee) GetPaymentSchedule() PaymentSchedule {
	return &MonthlySchedule{}
}
